package com.yuelan.codelib.utils;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.exmaple.baidumv.entity.HomeBannerEntity;
import com.exmaple.baidumv.entity.RankingEntity;

public class JsonUtil {

	public static ArrayList<RankingEntity> getRankingJson(JSONArray res){
		ArrayList<RankingEntity> arrayList = new ArrayList() ;
		
		  int iSize = res.length();  
		  LOG.v(res.length()+"");
          for (int i = 0; i < iSize; i++) {  
        		RankingEntity ranking = new RankingEntity();
              try {
				JSONObject resultObj = res.getJSONObject(i);
				ranking.setImgUrl(resultObj.getString("imgUrl"));
				ranking.setTags(resultObj.getString("tags"));
				ranking.setMvType(resultObj.getString("mvType"));
				
				ranking.setTimes(resultObj.getString("times"));
				ranking.setImgType(resultObj.getString("imgType"));
				ranking.setName(resultObj.getString("name"));
				
				ranking.setMs(resultObj.getString("ms"));
				ranking.setMvUrl(resultObj.getString("mvUrl"));
				ranking.setType(resultObj.getString("type"));
				ranking.setLongMs(resultObj.getString("longMs"));
				LOG.v(ranking.toString());
				
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
              
              arrayList.add(ranking);
            
          }  
          return arrayList;
	}
		
		
          public static ArrayList<HomeBannerEntity> getHomeJson(JSONArray res){
      		ArrayList<HomeBannerEntity> arrayList = new ArrayList() ;
      		
      		  int iSize = res.length();  
      		  LOG.v(res.length()+"");
                for (int i = 0; i < iSize; i++) {  
                	HomeBannerEntity ranking = new HomeBannerEntity();
                    try {
      				JSONObject resultObj = res.getJSONObject(i);
      				ranking.setImgUrl(resultObj.getString("imgUrl"));
      				ranking.setTags(resultObj.getString("tags"));
      				ranking.setMvType(resultObj.getString("mvType"));
      				
      				ranking.setTimes(resultObj.getString("times"));
      				ranking.setImgType(resultObj.getString("imgType"));
      				ranking.setName(resultObj.getString("name"));
      				
      				ranking.setMs(resultObj.getString("ms"));
      				ranking.setMvUrl(resultObj.getString("mvUrl"));
      				ranking.setType(resultObj.getString("type"));
      				ranking.setLongMs(resultObj.getString("longMs"));
      				LOG.v(ranking.toString());
      				
      			} catch (JSONException e) {
      				// TODO Auto-generated catch block
      				e.printStackTrace();
      			}  
                    
                    arrayList.add(ranking);
                  
                }  
		
		return arrayList;
	}
}
